package com.example.demo.controller;



import com.example.demo.entity.Image;
import com.example.demo.entity.Type;

import com.example.demo.service.Impl.TypeSelectImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

//类型操作接口
@RestController
@RequestMapping("/Type")
public class TypeController {

    TypeSelectImpl typeselectimpl=new TypeSelectImpl();

//    类型查找
    @ResponseBody
    @RequestMapping("/TypeSelect")
    public List<Type> TypeSelect(){
        List<Type> list=new ArrayList<>();
        try{
            list =typeselectimpl.TypeSelect();
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }

//    类型查找图片

    @RequestMapping("/TypeimgageSelect")
    public  List<Image> TypeimgageSelect(int type_id ){
        List<Image> list=new ArrayList<>();

        if(type_id!=0){
            try{
                list=typeselectimpl.TypeimgageSelect(type_id);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return list;
    }

//    修改类型名称

    @RequestMapping("/Typeupdate")
    public boolean Typeupdate(int type_id,String newType_name){
        if(type_id!=0&&newType_name!=""){
            try {
                typeselectimpl.Typeupdate(type_id, newType_name);
            }catch (Exception e){
                e.printStackTrace();
                return false;
            }
        }else {
            return false;
        }

        return true;
    }

//    增加类型
    @RequestMapping("/TypeAdd")
    public boolean TypeAdd(String Type_name){

        if(Type_name.length()!=0){
            try {
                typeselectimpl.TypeAdd(Type_name);
            }catch (Exception e){
                e.printStackTrace();
                return false;
            }
        }else {
            return false;
        }

        return true;
    }



//    删除类型
    @RequestMapping("/TypeDelete")
    public boolean TypeDelete(int Type_id){

        if(Type_id!=0){
            try {
                typeselectimpl.TypeDelete(Type_id);
            }catch (Exception e){
                e.printStackTrace();
                return false;
            }
        }else {
            return false;
        }

        return true;
    }

}

